package com.example.mypresentationdemo;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.mypresentationdemo.presentation.PresentionAddViewUtils;
import com.example.presentation_libary.ScreenStartServiceUtils;
import com.example.presentation_libary.constant.DefultConstants;
import com.example.presentation_libary.interfaces.ScreenStartServiceInterFace;

/**
 * @创建者： tjf
 * @创建时间： 2022/10/20 13:29
 * @描述： 双屏异显的测试页 启动服务的方式
 * 该demo只适合安卓板子的root下的测试   没有6.0 以上任何权限的请求   和服务 的前台设置
 * 有需求的需要添加相关运行时请求权限
 */
public class MainStartActivity extends AppCompatActivity implements ScreenStartServiceInterFace {

    private static final String TAG = "MainStartActivity";
    Button adv_auxiliary_tv, video_auxiliary_tv, close_auxiliary_bt, defult_auxiliary_bt, startServicePage;
    private String type;//副屏显示的屏幕布局类型
    private String json;//副屏显示的数据


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        defult_auxiliary_bt = findViewById(R.id.defult_auxiliary_bt);
        defult_auxiliary_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "=启动了默认副屏 ==");
                type = DefultConstants.PagePresentation.DEFAULT_AUXILIARY_SCREEN;
                json = "我是默认的副屏显示内容";
                startService();
            }
        });

        adv_auxiliary_tv = findViewById(R.id.adv_auxiliary_bt);
        adv_auxiliary_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "=启动了广告副屏 ==");
                type = Constants.PagePresentation.PRESENTATION_ADV;
                json = "我是广告的副屏显示内容";
                startService();
            }
        });

        video_auxiliary_tv = findViewById(R.id.video_auxiliary_bt);
        video_auxiliary_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "=启动了视频副屏 ==");
                type = Constants.PagePresentation.PRESENTATION_VIDEO;
                json = "我是视频的副屏显示内容";
                startService();
            }
        });

        close_auxiliary_bt = findViewById(R.id.close_auxiliary_bt);
        close_auxiliary_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "=关闭副屏 ==");
                ScreenStartServiceUtils.getInstance().close(MainStartActivity.this);
//                startActivity(new Intent(MainStartActivity.this,TwoActivity.class));
//                finish();
            }
        });

        startServicePage = findViewById(R.id.start_service_page_bt);
        startServicePage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "=启动绑定服务页 ==");
                startActivity(new Intent(MainStartActivity.this, MainActivity.class));
                finish();
            }
        });
    }

    /**
     * 启动双屏异显的服务
     * 注册回调时间及启动服务
     */
    private void startService() {
        ScreenStartServiceUtils.getInstance().setServiceInterFace(this);
        ScreenStartServiceUtils.getInstance()
                .startService(this);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
//        ScreenStartServiceUtils.getInstance().close(this);
    }

   /* @Override
    public void onBackPressed() {
        super.onBackPressed();
        System.exit(0);
    }*/

    @Override
    public void auxiliaryScreenStartsAndDisplaysSuccess() {
        ScreenStartServiceUtils.getInstance().setCallbackSecondaryScreenTypeAndContent(
                new PresentionAddViewUtils());
        ScreenStartServiceUtils.getInstance().addAuxiliaryScreenTypeAndContent(type, json);
    }
}